import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;

public class DateTest {
    /*设置格式化模板*/
    private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSS");
    /*设置日期时区常量*/
    private static final ZoneId CHINA_ZONE_ID = ZoneId.systemDefault();
    public static void main(String[] args) {
        /*Date格式化为DateTime*/
//        Date date = new Date();
//        System.out.println(date);
//        LocalDateTime localDateTime = date.toInstant().atZone(CHINA_ZONE_ID).toLocalDateTime();
//        System.out.println(localDateTime);
        /*LocalDate/LocalDateTime转Date*/
        //LocalDate
        LocalDate localDate = LocalDate.now();
        System.out.println(localDate);
        Date date1 = Date.from(localDate.atStartOfDay(CHINA_ZONE_ID).toInstant());
        System.out.println(date1);
        //LocalDateTime
        LocalDateTime localDateTime = LocalDateTime.now();
        System.out.println(localDateTime);
        Date date2 = Date.from(localDateTime.atZone(CHINA_ZONE_ID).toInstant());
        System.out.println(date2);
        /*日期格式化*/
        String format = LocalDateTime.now().format(DATE_TIME_FORMATTER);
        System.out.println(format);
    }
}
